$(function() {

	// 是否到达底部
	var buttom = false;
	var flag = false;

	// 请求更多的数据
	$(document).on("swipeup",function(){
			var winH =$(window).height();
			var myScroll = $(window).scrollTop();
			if(($(document).height()<= winH||($('body').height() - myScroll) <= winH )&&!buttom){
				console.log("到底了");
				buttom=true;
				var nextPage = $("#nextPage").val();
				var totalPage = $("#totalPage").val();
				if (Number(nextPage) <= Number(totalPage)) {// 如果当前页不是最后一页，则进行请求
					//如果不是第一页
					if(Number(totalPage)!=Number("1")){
						
						$(".slideToMore").hide();
						$(".loading").show();
						getMoreWithDrwalsMsg();
					}
				}else{
					$(".slideToMore").hide();
					//如果不是第一页,并且没有数据了，则提示到底了
					if(Number(totalPage)!=Number("1")){
						$(".slideToMore").text("到底了");
						$(".slideToMore").show();
					}
				}
			}
	})
	//获取更多的数据
	function getMoreWithDrwalsMsg() {

		var type = "";
		var status = "";
		var success = function(data) {
			
			//隐藏旋转框
            $(".slideToMore").show();
			$(".loading").hide();
			
			// 铺展数据
			for (var i = 0; i < data.length; i++) {
				var time = formatTime(data[i].createTime, 0);
				switch (data[i].withdrawalsType) {
				case 0:
					type = "银行卡";
					break;
				case 1:
					type = "微信钱包";
					break;
				default:
					break;
				}
				switch (data[i].withdrawalsStatus) {
				case 0:
					status = "提现中";
					break;
				case 1:
					status = "提现成功";
					break;
				case 2:
					status = "提现失败";
					break;
				default:
					break;
				}
				var jsonStr = '<div class="block withdrawal_info">'
						+ '<div class="withdrawal_price">'
						+ '<span class="status2">+' + data[i].money
						+ '</span>元' + '</div>' + '<div class="other_info">'
						+ '<p class="way">' + type + '</p>'
						+ '<p class="status">' + status + '</p>'
						+ '<p class="datetime">￥' + time + '</p>' + '</div>'
						+ '</div>';

				$("#content").append(jsonStr);

			}
			buttom = false;
			flag = false;
			var nextPage = $("#nextPage").val();
			var totalPage = $("#totalPage").val();
			if(Number(nextPage) <= Number(totalPage)){
				nextPage = Number(nextPage) + Number(1);
				$("#nextPage")[0].value=nextPage;
			}else{
				$(".slideToMore").hide();
			}

		}
		
		var error = function() {
			$(".slideToMore").show();
			$(".loading").hide();
			alert("请求失败");
			buttom = false;
			flag = false;
			$(window).scroll(scrollHandler);
		}
		var nextPage = $("#nextPage").val();
		var url = base_url+"customer/findWithDrawalsesByPage";
		var params="pageNum="+nextPage;
		doAjax("POST", url, params, success, error, true, false);
	}
})
